package com.example.testdemo.demos.web.Controller;

import com.example.testdemo.demos.web.Config.JwtInfo;
import com.example.testdemo.demos.web.Config.Result;
import com.example.testdemo.demos.web.Config.ResultEnum;
import com.example.testdemo.demos.web.Entity.Dict;
import com.example.testdemo.demos.web.Service.DictService;
import com.example.testdemo.demos.web.Service.JwtRedistService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/dict")
public class DictController {

    @Resource
    private DictService dictService;

    @Resource
    private JwtRedistService jwtRedistService;

    /**
     * 字典查询
     * @param dict
     * @param token
     * @return
     */
    @PostMapping("/queryDict")
    public Result queryDict(@RequestBody Dict dict,@RequestHeader("token") String token){
        Result result =new Result();
        try {
            JwtInfo jwtInfo =new JwtInfo();
            if (!(token.isEmpty())){
                jwtInfo =jwtRedistService.getUserInfo(token);
            }else {
                jwtInfo.setPass(false);
            }
            return dictService.queryDict(dict,jwtInfo);
        }catch (Exception e){
            result.setCode(ResultEnum.FORBIDDEN.getCode());
            result.setMsg(ResultEnum.FORBIDDEN.getData());
        }
        return result;
    }
}
